package com.dz.finance.biz.service.impl;

import com.dz.finance.biz.constant.MsgConstant;
import com.dz.finance.biz.entity.Tenant;
import com.dz.finance.biz.mapper.TenantMapper;
import com.dz.finance.biz.service.TenantService;
import com.dz.finance.common.exception.BizException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @author: DengHaoQi
 * @date: 2024/5/31 19:30
 * @description: 租户ServiceImpl
 */

@Slf4j
@Service
@RequiredArgsConstructor
public class TenantServiceImpl implements TenantService {

    private final TenantMapper tenantMapper;

    @Override
    public Long addTenant() {
        Tenant tenant = new Tenant();
        tenant.initDefault();
        int row = tenantMapper.insert(tenant);
        if (row == 0) {
            log.error("租户创建失败");
            throw new BizException(MsgConstant.TENANT_CREATE_FAIL);
        }
        return tenant.getId();
    }
}
